<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>添加场地参观预约 - ${siteName}</title>
<meta name="description" content="">
<meta name="author" content="xuzewei">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/cloud-admin.css">
<link rel="stylesheet" type="text/css" href="css/themes/default.css"
	id="skin-switcher">
<link rel="stylesheet" type="text/css" href="css/responsive.css">
<link rel="stylesheet" type="text/css"
	href="font-awesome/css/font-awesome.min.css">
<!-- JQUERY UI-->
<link rel="stylesheet" type="text/css"
	href="js/jquery-ui-1.10.3.custom/css/custom-theme/jquery-ui-1.10.3.custom.min.css" />
<!-- DATE RANGE PICKER -->
<link rel="stylesheet" type="text/css"
	href="js/bootstrap-daterangepicker/daterangepicker-bs3.css" />
<!-- JQGRID -->
<link rel="stylesheet" type="text/css"
	href="js/jqgrid/css/ui.jqgrid.min.css" />
<!-- HUBSPOT MESSENGER -->
<link rel="stylesheet" type="text/css"
	href="js/hubspot-messenger/css/messenger.min.css" />
<link rel="stylesheet" type="text/css"
	href="js/hubspot-messenger/css/messenger-theme-flat.min.css" />
<link rel="stylesheet" href="zhubajie/css/base.css" />
<link rel="stylesheet" href="zhubajie/css/main.css" />
<style type="text/css">
		.leaseimg1{
			background-color: #ffffff;
			}
		.leaseimg2{
			background-color:#808080;
		}
		.leaseimg3{
			background-color:#00FFFF;
		}
	</style>
</head>
<body id="app" ng-app="app" ng-controller="ctrl">
	<!-- HEADER -->
	<jsp:include page="include/header.jsp" />
	<!--/HEADER -->
	<!-- PAGE -->
	<section id="page">
		<!-- SIDEBAR -->
		<jsp:include page="include/sidebar.jsp" />
		<!-- /SIDEBAR -->
		<div id="main-content">
			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- BREADCRUMBS -->
									<ul class="breadcrumb">
										<li><i class="fa fa-home"></i> <a href="welcome.jsp">Home</a>
										</li>
									</ul>
									<!-- /BREADCRUMBS -->
									<div class="clearfix">
										<h3 class="content-title pull-left">添加会议预约</h3>
									</div>
									<div class="description"></div>
								</div>
							</div>
						</div>
						<!-- /PAGE HEADER -->
						<div class="box border orange">
							<div class="box-title">
								<h4>
									<i class="fa fa-bars"></i>添加会议预约
								</h4>
							</div>
							<div class="box-body big">
								<form role="form">
									<div class="form-group">
										<label>公司名称</label> <select ng-model="entrepreneurId" class="form-control"
											ng-options="o.entrepreneurId as o.name for o in allEntrepreneur" >
											<option value="">-- 请选择 --</option>
										</select>
									</div>
									<div class="form-group">
										<label>联系人</label> <input type="text" class="form-control"
											ng-model="name">
									</div>
									<div class="form-group">
										<label>联系方式</label> <input type="text" class="form-control"
											ng-model="phone">
									</div>
									<div class="form-group">
										<label>选择会议室</label> <select ng-model="meetingRoomId" class="form-control"
											ng-options="o.meetingRoomId as o.name for o in address1" ng-change="schedule()" >
											<option value="">-- 请选择 --</option>
										</select>
									</div>
									<section class="line addr_line"></section>
									<section class="mt">
										<table id="schedule1" class="addr_table boardroom-table tc" cellpadding="0" cellspacing="0">
										</table>
										<p class="tc">
											<span class="diamond">您预定的时间</span> <span
												class="diamond diamond_right">已经被锁定</span>
										</p>
									</section>
									<button type="submit" class="btn btn-danger" ng-click="submit()">提交</button>
								</form>
							</div>
						</div>
						<div class="footer-tools">
							<span class="go-top"> <i class="fa fa-chevron-up"></i> Top
							</span>
						</div>
					</div>
					<!-- /CONTENT-->
				</div>
			</div>
		</div>
	</section>
	<!--/PAGE -->

	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY -->
	<script src="js/jquery/jquery-2.0.3.min.js"></script>
	<!-- JQUERY UI-->
	<script
		src="js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="bootstrap-dist/js/bootstrap.min.js"></script>
	<!-- DATE RANGE PICKER -->
	<script src="js/bootstrap-daterangepicker/moment.min.js"></script>
	<script src="js/bootstrap-daterangepicker/daterangepicker.min.js"></script>
	<!-- SLIMSCROLL -->
	<script type="text/javascript"
		src="js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
	<script type="text/javascript"
		src="js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
	<!-- BLOCK UI -->
	<script type="text/javascript"
		src="js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
	<!-- JQGRID -->
	<script type="text/javascript" src="js/jqgrid/js/grid.locale-en.min.js"></script>
	<script type="text/javascript" src="js/jqgrid/js/jquery.jqGrid.min.js"></script>
	<!-- COOKIE -->
	<script type="text/javascript"
		src="js/jQuery-Cookie/jquery.cookie.min.js"></script>
	<!-- HUBSPOT MESSENGER -->
	<script type="text/javascript"
		src="js/hubspot-messenger/js/messenger.min.js"></script>
	<script type="text/javascript"
		src="js/hubspot-messenger/js/messenger-theme-flat.js"></script>
	<script type="text/javascript"
		src="js/hubspot-messenger/js/messenger-theme-future.js"></script>
	<script src="js/script.js"></script>
	<!-- CLOSURE-LIBRARY -->
	<script src="closure-library/closure/goog/base.js"></script>
	<!-- ANGULAR-LIBRARY -->
	<script src="angular-1.5.0-rc.2/angular.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="include/common.js"></script>
	<script>
		var app = angular.module("app", []);
		app.controller('ctrl',function($scope, $http, $httpParamSerializer,$injector, $window) {
				//获取会议室
				$scope.address1 = function() {
					var reqConfig = {headers : {"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8"}};
						$http.post("api/meetingRoomAction/queryByMemberId",reqConfig)
							.success(function(data, status) {
									if (isErr(data)) {
										showErrMsg(data);
										return;
										}
									$scope.address1=data.response;
							}).error(
									function(data, status) {
									showNetworkErrMsg(data,status);
							});
					};
				$scope.submit = function() {
					var items=document.getElementsByName("meetingTimes");
					var arr=new Array();
					var date1=new Date();
					var i=0;
						for(var x=0;x<items.length;x++){
							if(items[x].checked){
								date1= items[x].value;
								 arr[i] = date1;
								 i++;
								}
							}
					if(arr.length==0||arr.length<0){
						showMsg("至少选一个");
					}else{
					var param = {
							"meetingRoomId":$scope.meetingRoomId,
							"entrepreneurId" : $scope.entrepreneurId,
							"name" : $scope.name,
							"phone" : $scope.phone,
							"orderTimes":arr
							
					};
				jQuery.post("api/meetingOrderAction/add",param, function(data) {
						isErr(data) ? showErrMsg(data): showMsg('添加场地参观预约成功！');
									});
					}
				}
				
			//通过会议室查询所有meeting对象
			$scope.findByAddressAll = function() {
				var reqDate = jQuery.param({
					"meetingRoomId":$scope.meetingRoomId
				});
				var reqConfig = {headers : {"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8"}};
					$http.post("api/meetingOrderAction/findByAddressAll",reqDate,reqConfig)
						.success(function(data, status) {
								if (isErr(data)) {
									showErrMsg(data);
									return;
									}
								$scope.meetings=data.response;
						}).error(
								function(data, status) {
								showNetworkErrMsg(data,status);
						});
				}
			
				$scope.queryAllEntrepreneur = function() {
					var reqDate = jQuery.param({});
					var reqConfig = {headers : {"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8"}};
					$http.post("api/allianceEntrepreneur/allEntrepreneur",reqDate, reqConfig)
						.success(function(data, status) {
								if (isErr(data)) {
									showErrMsg(data);
									return;
												}
						$scope.allEntrepreneur = data.response;
						}).error(
									function(data, status) {
									showNetworkErrMsg(data,status);
						});
				}
		//生成时间表
	 	$scope.schedule=function(){
	 		initNumber();
			var currentTime=new Date();
			var month=currentTime.getMonth()+1;
			var meetingTimes=$scope.meetings;
			var reqDate = jQuery.param({
				"meetingRoomId":$scope.meetingRoomId
			});
			var b=$scope.entrepreneurId;
			if(b==''||b==null||b=='undefined'){
				showMsg('请选择公司！');
				return;
			}else{
			var reqConfig = {headers : {"Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8"}};
			$http.post("api/meetingOrderAction/findByAddressAll",reqDate,reqConfig)
				.success(function(data, status) {
						if (isErr(data)) {
							showErrMsg(data);
							return;
							}
						$scope.meetings=data.response;
				
			jQuery('#schedule1').empty();
			for(var i=0;i<15;i++){
				jQuery('#schedule1').append("<tr id='tr"+i+"'></tr>");
				for(var j=0;j<8;j++){
					if(i==0){
						if(j==0){
							jQuery("#tr"+i).append("<td >"+month+"月</td>");
							}else {
								var a=0;
								if(j==1){
									a=0;
								}else{
									a=1;
								}
								currentTime.setDate(currentTime.getDate()+a);
								var day=currentTime.getDate();
								jQuery("#tr"+i).append("<td >"+day+"日</td>");
							}
					}else
					if(i==1){
						if(j==0){
							jQuery("#tr"+i).append("<td>星期</td>");
							}else {
								var a=0;
								if(j==1){
									a=-7;
								}else{
									a=1;
								}
								var show_day=new Array('一','二','三','四','五','六','日');
								currentTime.setDate(currentTime.getDate()+a);
								var days=currentTime.getDate()+1;
								var day=currentTime.getDay();
								jQuery("#tr"+i).append("<td   >"+show_day[day]+"</td>");
							}
					}else if(j%8==0){
						var b=i+7;
						var c=i+8;
						jQuery("#tr"+i).append("<td >"+b+"-"+c+"</td>");
					}else{	
							var a=0;
							if(j==1){
								a=-6;
							}else{
								a=1;
							}
						 	var falge=false;
							currentTime.setDate(currentTime.getDate()+a);
							var meetingTimes=$scope.meetings;
							var year2=currentTime.getFullYear();
							var month2=currentTime.getMonth()+1;
							var currentTime1=new Date();
							currentTime1.setDate(currentTime.getDate()+1);
							var day2=currentTime1.getDate();
							var hours2=currentTime.getHours();
						 	for(var f=0;f<meetingTimes.length;f++){
						 		var times=meetingTimes[f].times;
						 		var str=times.split(',');
						 		for(y=0;y<str.length;y++){
						 			var str1=str[y].split('-');
									var years=str1[0];
									var months=str1[1];
									var days=str1[2];
									var hourss=str1[3];
									var hoursc=i+7;
									if(year2!=years||month2!=months){
										break;
									}
									if(days==day2&&hoursc==hourss){
										falge=true;
										break;
									}
						 		} 
							} 
							if(falge){
								jQuery("#tr"+i).append("<td class='leaseimg2'> </td>");
							}else{ 
							jQuery("#tr"+i).append("<td id=td"+i+j+" onclick='clickChange("+i+j+")'>"
							+"<input type='checkbox' id=meeting"+i+j+" name='meetingTimes' value='"+currentTime+","+(i+7)+"' style='display:none;'>"
							+"<input type='hidden' id='sequence"+i+j+"' value='"+day2+","+i+"'>"
							+"<input id=status"+i+j+" value='0' style='display:none;'>"
							+" </td>");
							}
					}
					
				}
			
			}
				}).error(
						function(data, status) {
						showNetworkErrMsg(data,status);
				});
			}
		} 
		//通过公司Id查询Entrepreneur
		$scope.queryByNameEntrepreneur = function() {
			var reqDate = jQuery.param({
				"id":$scope.entrepreneurId
			});
			var reqConfig = { headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} };
			$http.post(
				"api/allianceEntrepreneur/queryById", reqDate, reqConfig
			).success(function(data, status) {
				if (isErr(data)) {
					showErrMsg(data);
					return;
				}
				$scope.entrepreneur = data.response;
			}).error(function(data, status) {
				showNetworkErrMsg(data, status);
			});
		};
			$scope.logout = function() {
				logout($window);
							};
						});
		
		var a=0;
		var b=0;
		var f=0;
		var h=0;
		//初始化数据
		function initNumber(){
			a=0;
			b=0;
			f=0;
			h=0;
		}
		function clickChange(value){
			var stat=document.getElementById("status"+value).value;
			if(stat==0){
				var sequence=document.getElementById("sequence"+value).value;
				var str=sequence.split(",");
				if((a==null&&b==null)||(a==0&&b==0)){
					a=str[0];
					b=str[1];
					f=str[1];
					h=str[1];
					document.getElementById("td"+value).style.background= "#DC143C";
					var stationStatus=document.getElementById("meeting"+value);
					stationStatus.checked=true;
					document.getElementById("status"+value).value=1;
				}else{
					var c=str[0];
					var d=str[1];
					if(a==c){
						var e=parseInt(d)-1;
						var g=parseInt(d)+1;
						if(e==b||g==h){
							document.getElementById("td"+value).style.background= "#DC143C";
							var stationStatus=document.getElementById("meeting"+value);
							stationStatus.checked=true;
							document.getElementById("status"+value).value=1;
							if(h==g){
								h=d;
								f=d;
							}else{
								b=d;
							}
						}else{
							alert("请选择连续时间");
							return;
						}
					}else{
						alert("一次只能预约天一如果想在预约多天请多次下订单");
						return;
					}
				}
			}else{
				var sequence=document.getElementById("sequence"+value).value;
				var str=sequence.split(",");
				var c=str[0];
				var d=str[1];
				if(c==a){
					if(b==d){
					document.getElementById("td"+value).style.background= "#ffffff";
					var stationStatus=document.getElementById("meeting"+value);
					stationStatus.checked=false;
					document.getElementById("status"+value).value=0;
					if(d==f){
						a=0;
						b=0;
						f=0;
					}else{
						b=parseInt(d)-1
						}
					}else{
						alert("请从最后一个时间段递减");
						return;
					}
				}else{
					alert("请从最后一个时间段递减");
					return;
				}
			}
		};
	</script>
	<script>
		jQuery(document).ready(function() {
			App.init();
			jQuery('#nav_resource-manage').click();
			setTimeout(function() {
				var scope=angular.element('#app').scope();
				scope.queryAllEntrepreneur();
				scope.address1();
			}, 500);
		});
	</script>
	<!-- /JAVASCRIPTS -->
</body>
</html>